#ifndef _featureCreatio_H_
#define _featureCreatio_H_

#include <algorithm>

#include <vector>

#include "NearestMeanClassifier.h"
#include "ImageMean.h"
#include "Sample.h"
#include "DataSet.h"
//#include "filter.h"
#include "Image.H"
#include "IO.H"
#include "Util.H"
//#include "graymorphology.h"
#include "unskew.h"
//#include "skel.h"
//#include "redlesiondetection.h"


using namespace std;
using namespace pip;



// a function that pushes pixels(2D) into a vector
void pixel_extract(const Image<unsigned char>& in, vector<float>& h)
{
	h.clear(); // clear vector to avoid side-effects
	for(int x=0;x<in.dim(0);++x){
		for(int y=0;y<in.dim(1);++y){
			h.push_back(float(in(x,y)));
		}
	}
}

// here the samples are created out of labels and digits
void getFeatureLabels(const string images,
                      DataSet& ds,
					  string labels = ""
                      )
{
  Image<unsigned char> labs;
  Image<unsigned char> data;
  Image<unsigned char> in;
  Image<unsigned char> in2;
  vector<float> v;

  if( !importFile(data, images)){
	  error("while parsing trainings data: ", "Usage:  -trainImages FILENAME  is not set proper.");
  }
  
  unsigned int depth = data.dim(2);

  if(labels.length()<1){
	  cout << "no labels passed: assuming test-data."<<endl;
	  labs.resize(Dimension(depth,1));
  }
  else if(!importFile(labs, labels)){
	  error("while parsing trainings data: ", "Usage:  -trainLabels FILENAME  is not set proper.");
  }
  
  for (unsigned int i = 0; i < depth; ++i) {
	in=data.sliced(2,i);
	//s.thin(in);
	unskew(in);
	pixel_extract(in, v);  	
	Sample s(v, int(labs(i,0)));
	if(!(i%1000))
	  cout << "\n" << i << "\t ";
	else if(!(i%25))
	  cout << ".";
    ds.push_back(s);
  }

}

#endif